package com.ysd.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.ysd.entity.XiYangYangChaoShi;
import com.ysd.util.DBManager;

public class XiYangYangChaoShiDaoimpl {
	/**
	 * 获得喜洋洋超市的数据
	 * @return
	 */
	public XiYangYangChaoShi getXiYangYangCahoShi() {
		Connection conn=DBManager.getConnection();
		XiYangYangChaoShi xiyangyang=null;
		Statement st=null;
		ResultSet rs=null;
		try {
			 st=conn.createStatement();
			String sql="SELECT * FROM xiyangyangchaoshi";
			 rs=st.executeQuery(sql);
			while(rs.next()) {
				 xiyangyang=new XiYangYangChaoShi(rs.getString("chaoShiName"), rs.getString("logo"), rs.getString("chaoShiJieShao"), rs.getString("chaoShiDianHua"), rs.getString("chaoShiYouXiang"), rs.getString("chaoShiWangZhi"), rs.getString("chaoShiDiZhi"), rs.getString("qiYeWenHua"), rs.getString("chaoShiXiangJie"), rs.getString("chaoShiErWeiMa"),rs.getInt("id"));
			}
			return xiyangyang;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally {
			DBManager.closeAll(conn, st, rs);
		}
		
	}
	/**
	 * 通过id查询数据
	 * @param id
	 * @return
	 */
	public XiYangYangChaoShi getXiYangYangChaoShiById(int id) {
		Connection conn=DBManager.getConnection();
		XiYangYangChaoShi xiyangyang=null;
		Statement st=null;
		ResultSet rs=null;
		try {
			 st=conn.createStatement();
			String sql="SELECT * FROM xiyangyangchaoshi where id="+id;
			 rs=st.executeQuery(sql);
			while(rs.next()) {
				 xiyangyang=new XiYangYangChaoShi(rs.getString("chaoShiName"), rs.getString("logo"), rs.getString("chaoShiJieShao"), rs.getString("chaoShiDianHua"), rs.getString("chaoShiYouXiang"), rs.getString("chaoShiWangZhi"), rs.getString("chaoShiDiZhi"), rs.getString("qiYeWenHua"), rs.getString("chaoShiXiangJie"), rs.getString("chaoShiErWeiMa"),rs.getInt("id"));
			}
			return xiyangyang;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally {
			DBManager.closeAll(conn, st, rs);
		}
	}
	
	/**
	 * 通过id修改喜洋洋超市
	 * @param x
	 * @return
	 */
	public int editXiYangYangChaoShiById(XiYangYangChaoShi x) {
		return DBManager.executeUpdate("UPDATE xiyangyangchaoshi SET chaoShiName='"+x.getChaoShiName()+"',logo='"+x.getLogo()+"',chaoShiXiangJie='"+x.getChaoShiXiangJie()+"',chaoShiDianHua='"+x.getChaoShiDianHua()+"',chaoShiYouXiang='"+x.getChaoShiYouXiang()+"',chaoShiWangZhi='"+x.getChaoShiWangZhi()+"',chaoShiDiZhi='"+x.getChaoShiDiZhi()+"',qiYeWenHua='"+x.getQiYeWenHua()+"',chaoShiXiangJie='"+x.getChaoShiXiangJie()+"',chaoShiJieShao='"+x.getChaoShiJieShao()+"',chaoShiErWeiMa='"+x.getChaoShiErWeiMa()+"' where id="+x.getId());
	}
}
